<template>
  <view class="view_box">
    <navBar :navbarData.sync="navbarData"></navBar>
    <view v-if="showTips === 1 && utoolsData">
      <utools-parse
        id="utools-parse"
        page="category"
        @triggerComponent="onTriggerComponent"
        @setPanel="setPanel"
        :utools-data="utoolsData"
        @onAddCart="onAddCart"
      ></utools-parse>
    </view>
    <view v-if="showTips === 2" class="no_text"> 暂无内容 </view>
    <view class="ios_safe_zone" v-if="isIos">
      <view class="ios_safe_zone_line"></view>
    </view>
  </view>
</template>

<script>
let observer = null;
import api from "@/api/api";
import NavBar from "../../components/common/navbar";
export default {
  components: {
    navBar: NavBar,
  },
  data() {
    return {
      utoolsClassGoodsLists: null,
      utoolsData: null,
      showTips: 0,
      navbarData: {
        showCapsule: 0, //是否显示左上角图标   1表示显示    0表示不显示
        title: "", //导航栏 中间的标题
        newLogo: uni.getStorageInfoSync("storeLogo"),
        isTopFixed: false,
        navbarDataShowHome: 1, //home图标
        navbarDataShowHomeColor: 1, //1 黑 2白
      },
      isIos: false,
    };
  },
  async onLoad(option) {
    await this.init(option);
    this.isIos =
      wx.getSystemInfoSync().system.includes("iOS") &&
      wx.getSystemInfoSync()?.safeArea?.top > 20;

    //200周年落地页浏览
    this.$commonSensors.lithaTrack.crTrack("TwoHundredYLandingPageView", {});
  },
  onHide() {},
  methods: {
    async init(option) {
      let _utoolsData = await this.getUtoolsData(option);
      if (!_utoolsData) return (this.showTips = 2);
      this.utoolsData = _utoolsData;
      this.showTips = 1;
      return null;
    },
    /**
     * 获取utools数据
     * @param {Object} option
     */
    async getUtoolsData(option) {
      try {
        let json = await api.getUtoolsJson({
          type: "y200",
        });
        return json.success && json?.data ? JSON.parse(json.data) : null;
      } catch (e) {
        return null;
      }
    },

    // 200周年落地页点击
    onTriggerComponent(option) {
      const { trackData = null } = option.detail.data;
      if (trackData) {
        const _trackData = JSON.parse(trackData);
        this.$commonSensors.commonPageClick(
          "TwoHundredYLandingPageClick",
          _trackData.data.button_name || ""
        );
      }
    },
  },
};
</script>

<style lang="less">
.view_box {
  position: relative;
}

.no_text {
  width: 100%;
  text-align: center;
  font-family: NotoSansSC-Regular;
  font-size: 28rpx;
  font-weight: 500;
  margin-top: 300rpx;
  color: #757575;
}
</style>